package com.one.material.feign;

import com.alibaba.fastjson.JSONArray;
import com.one.material.entity.Material;
import com.one.material.struct.PageResult;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.ArrayList;

/**
 * 降级处理
 * @author windows
 */
@Component
public class FeignMaterialFallback implements FallbackFactory {
    @Override
    public FeignMaterial create(Throwable throwable) {
        return new FeignMaterial() {
            @Override
            public String getMaterialAll() {
                // 降级
                ArrayList<Material> materials = new ArrayList<>();
                Material material = new Material();
                material.setMaterialCode("服务已停止使用");
                materials.add(material);
                return JSONArray.toJSONString(materials);
            }

            @Override
            public PageResult<Material> getMaterialPageAll(Material material, Integer pageNum, Integer pageSize) {
                return null;
            }
        };
    }
}
